package cn.seecoder.courselearning.controller.post;


import cn.seecoder.courselearning.service.course.CourseService;
import cn.seecoder.courselearning.service.post.PostService;
import cn.seecoder.courselearning.util.Constant;
import cn.seecoder.courselearning.vo.ResultVO;
import cn.seecoder.courselearning.vo.course.CourseVO;
import cn.seecoder.courselearning.vo.post.PostVO;

import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/post")
public class PostController {
    @Resource
    private PostService postService;

    //发帖
    @PostMapping("/create")
    public ResultVO<PostVO> createPost(@RequestBody PostVO postVO) {
        return postService.createPost(postVO);
    }

    //获取访问讨论区权限
    @GetMapping("/priority")
    public boolean getPriority(@RequestParam Integer uid,@RequestParam Integer courseId){
        return postService.getPriority(uid,courseId);
    }


    //获取按照最新发布时间倒序帖子列表
    @GetMapping("/timePostList/{page}")
    public PageInfo<PostVO> getPostByPostTime (@RequestParam(required = false, defaultValue = "")  Integer uid,
                                               @RequestParam Integer cid,
                                               @PathVariable Integer page) {
        return postService.getPostByPostTime(page, Constant.COURSE_PAGE_SIZE, uid, cid);
    }

    @GetMapping("/replyPostList/{page}")
    public PageInfo<PostVO> getPostByLastReplyTime (@RequestParam(required = false, defaultValue = "")  Integer uid,
                                                    @RequestParam Integer cid,
                                                    @PathVariable Integer page) {
        return postService.getPostByLastReplyTime(page, Constant.COURSE_PAGE_SIZE, uid, cid);
    }
    //查询单个帖子
    @GetMapping("/{postId}")
    public ResultVO<PostVO> getPost(@RequestParam(required = false, defaultValue = "") Integer uid, @PathVariable Integer postId) {
        return postService.getPost(postId, uid);
    }
}
